<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击</button>
    <script>
        let obj = {
            name:'zhangsan',
            age: 20
        }
        // 跳转的同时 携带obj参数
        document.querySelector('button').onclick = () => {
            window.location.href = `other.html?${o2s(obj)}`
        }
        function o2str(obj) {
            let keys = Object.keys(obj)
            let values = Object.values(obj)
            var arr = keys.map((item, index) => {
                return `${item}=${values[index]}`
            })
            return '?' + arr.join('&')
        }
        //上面的简写
        const o2s = obj=>Object.keys(obj).map((key,index)=>`${key}=${Object.values(obj)[index]}`).join("&");
        
    </script>
</body>

</html>